<?php
/*
 * inc-student.php
 * Retral/CSCD494 Winter 2009
 * Eastern Washington University
 *
 * File Description:
 * Show exams and info on a student with student id "id"
 * 
 * Other:
 * 
 */
?>

<span class="header-text">Student Info</span><br>
<?php
	if(!isset($_REQUEST['id'])) {
		/* TODO: Code that requests the person to enter in
		 * a students id to continue.
		 */
		print "<p> Still needs work</p>";
	} else {
		$conn = oci_connect(ORA_CON_UN, ORA_CON_PW, ORA_CON_DB);

		$studentID = $_REQUEST['id'];

		print "<h2>Student #$studentID</h2>";

		$query = '
			SELECT DISTINCT exam.exam_id, exam.date_scheduled FROM exam
			INNER JOIN student_question ON exam.exam_id=student_question.exam_id
			WHERE student_question.student_id=:SID';

		$stmtExams = oci_parse($conn, $query);
		oci_bind_by_name($stmtExams, ':SID', $studentID);
		if(!oci_execute($stmtExams)) 
			print "<P>Could not query for Student</P>";

		$query = '
SELECT grade, question_content.points, question_content.question_title, notes
			FROM student_question INNER JOIN question 
			ON student_question.question_id =question.question_id
			INNER JOIN question_content 
			ON question.question_content_id=question_content.question_content_id
      INNER JOIN exam_question ON exam_question.question_id=question.question_id
			WHERE student_id=:SID AND exam_id=:examID';

		$stmt = oci_parse($conn, $query);

		while($row = oci_fetch_assoc($stmtExams)) {
			oci_bind_by_name($stmt, ':examID', $row['EXAM_ID']);
			oci_bind_by_name($stmt, ':SID', $studentID);
			if(!oci_execute($stmt)) 
				print "<P>Could not query for Exam</P>";

			print "<h3>Exam <a href='?page=preview&exam=".$row['EXAM_ID'];
			print "'>".dateFormat($row["DATE_SCHEDULED"])."</a></h3>";
			startTable();
			
			while($q = oci_fetch_assoc($stmt)) {
				print "\t<tr><td>".$q['QUESTION_TITLE']."</td>";
				print "<td>".$q['GRADE']."/".$q['POINTS']."</td>";
				print "<td>".$q['NOTES']."</td></tr>\n";
			}

			print "</table>";

		}

		oci_free_statement($stmt);
		oci_free_statement($stmtExams);
		oci_close($conn);
	}

function startTable() {
?>

<table>
	<tr><td width=170><u>Question</u></td><td width=50><u>Grade</u></td><td><u>Notes</u></td>
<?PHP
}
?>
